package com.czl.module_storehouse.mvp.model;

import com.czl.base.data.net.RetrofitClient;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_storehouse.api.ApiService;
import com.czl.module_storehouse.bean.AddMoveInfoBean;
import com.czl.module_storehouse.bean.AllocateBean;
import com.czl.module_storehouse.bean.AllocateInBean;
import com.czl.module_storehouse.bean.AllocateOutBean;

import org.json.JSONObject;

import io.reactivex.Observable;

/**
 * @author by xubin,
 * @date on 2022/2/16.
 * PS: Not easy to write code, please indicate.
 */
public class AllocateModel extends BasicDataModel {

    public Observable<HttpResponse<Object>> addMoveInfo(AddMoveInfoBean bean) {
        bean.setMovePersonName(getTName());
        bean.setMovePersonId(getUserId());
        bean.setMoveStorehouseId(getStorehouseId());
        bean.setMoveCompanyId(getManageCompanyId());
        return RetrofitClient.getInstance().create(ApiService.class)
                .addMoveInfo(createBody(bean));
    }

    public Observable<HttpResponse<ListBean<AllocateBean>>> getNeedDealtMoveList(int pageNo) {
        return RetrofitClient.getInstance().create(ApiService.class)
                .getNeedDealtMoveList(getRequestBodyByStorehouseIdPageNo(pageNo));
    }

    public Observable<HttpResponse<ListBean<AllocateBean>>> getDealtMoveList(int pageNo) {
        return RetrofitClient.getInstance().create(ApiService.class)
                .getDealtMoveList(getRequestBodyByStorehouseIdPageNo(pageNo));
    }

    public Observable<HttpResponse<Object>> editMoveInfo(AllocateOutBean bean) {
        bean.setMovePersonName(getTName());
        bean.setMovePersonId(String.valueOf(getUserId()));
        return RetrofitClient.getInstance().create(ApiService.class)
                .editMoveInfo(createBody(bean));
    }

    public Observable<HttpResponse<Object>> moveStorage(AllocateInBean bean) {
        bean.setInPersonName(getTName());
        bean.setInPersonId(getUserId());
        return RetrofitClient.getInstance().create(ApiService.class)
                .moveStorage(createBody(bean));
    }

    public Observable<HttpResponse<AllocateBean>> getNeedDealtMoveNewSortInfo(int moveId) {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", getManageCompanyId());
            object.put("moveId", moveId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RetrofitClient.getInstance().create(ApiService.class)
                .getNeedDealtMoveNewSortInfo(createBody(object));
    }
}
